
<template>
  <div class="update-gender">
      <!-- 性别组件 -->
    <van-picker
      title="性别"
      show-toolbar
      :columns="columns"
      :default-index="localGender"
      @cancel="$emit('close')"
        @confirm="onConfirm"
      @change="onChange"
    />
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user'
export default {

  props: {
    value:{
      type:Number,
      required:true
    }
  },
  data () {
    return {
      columns: ['男', '女'],
       localGender: this.value
    }
  },methods:{
    async onConfirm(){
        this.$toast.loading({
            message: '更新中...',
            forbidClick: true,
            loadingType: 'spinner',
            duration:0
        });
       try {
        
       
         const res= await  updateUserProfile({
          gender: this.localGender
        })
        
        this.$emit('input',this.localGender)
 this.$toast.success('更新成功');
          // 关闭弹层
          this.$emit('close')
 
       } catch (err) {
        console.log(err);
         this.$toast.fail('更新失败');
       }
       
     },
     onChange(picker, value, index) {
       this.localGender = index
    },
  
  },

  }

</script>

<style scoped lang='less'>

</style>